﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace PixelWarfare
{
    public partial class PixelWarfareForm : Form
    {
        private Timer main_loop;        // The timer to execute constantly at certain intervals.
        
        public PixelWarfareForm()
        {
            InitializeComponent();           
            main_loop = new Timer();
        }

        private void PixelWarfareForm_Load(object sender, EventArgs e)
        {
            Control.Init();

            // Setup the timer event.
            main_loop.Interval = 10;
            main_loop.Tick += new EventHandler(Update);
            main_loop.Start();
        }

        private void PixelWarfareForm_Paint(object sender, PaintEventArgs e)
        {
            Control.Draw(e.Graphics);
        }

        private void PixelWarfareForm_FormClosed(object sender, FormClosedEventArgs e)
        {
            Application.Exit();
        }

        private void PixelWarfareForm_MouseDown(object sender, MouseEventArgs e)
        {
            Control.MousePress(e.X, e.Y);
        }

        private void PixelWarfareForm_MouseUp(object sender, MouseEventArgs e)
        {
            Control.MouseRelease(e.X, e.Y);
        }

        private void PixelWarfareForm_MouseMove(object sender, MouseEventArgs e)
        {
            Control.MouseMove(e.X, e.Y);
        } 

        private void PixelWarfareForm_KeyDown(object sender, KeyEventArgs e)
        {
            Control.KeyPress(e.KeyCode);
        }

        private void PixelWarfareForm_KeyUp(object sender, KeyEventArgs e)
        {
            Control.KeyRelease(e.KeyCode);
        }

        private void Update(object sender, EventArgs e)
        {
            Control.Update();
            Invalidate();
        }            
    }
}
